#include "../observer.h"

#include <iostream>
#include <memory>
#include <vector>
#include <mutex>
#include <functional>
#include <algorithm>
#include <queue>
#include <future>
#include <atomic>

int main()
{
  auto observable = std::make_shared<good_cptl::Observable<std::string>>();

  // 创建不同的观察者（不同优先级）
  struct LogObserver : public good_cptl::Observer<std::string>
  {
    LogObserver(int priority = 0) : Observer(priority) {}
    void on_update(const std::string& data) override {
      std::cout << "LogObserver: " << data << std::endl;
    }
  };

  struct AlertObserver : public good_cptl::Observer<std::string>
  {
    AlertObserver(int priority = 0) : Observer(priority) {}
    void on_update(const std::string& data) override {
      std::cout << "AlertObserver: " << data << std::endl;
    }
  };

  observable->add_observer(std::make_shared<LogObserver>(), 1);
  observable->add_observer(std::make_shared<AlertObserver>(), 2);

  observable->notify("Sync Message 1");
  observable->notify("Sync Message 2");

  // 异步通知
  observable->async_notify("Async Message 1");
  observable->async_notify("Async Message 2");

  std::this_thread::sleep_for(std::chrono::seconds(1));  // 等待异步任务完成
  return 0;
}